<?php
/** 依赖对象，由chulidu */
class DependentObject1
{
	/** @var string $data */
    private $data;
    public function setData($data)
    {
       $this->data = $data; 
    }
    public function getData()
    {
       return $this->data;
    }
}
class DependentObject2
{
	/** @var string $data */
    private $data;
    public function setData($data)
    {
       $this->data = $data; 
    }
    public function getData()
    {
       return $this->data;
    }
}
class CoarseGrainedObject
{
    /** @var DependentObject1 $do1 */
    protected $do1;
    /** @var DependentObject2 $do2 */
    protected $do2;
    public function __construct()
    {
        $this->do1 = new DependentObject1;
        $this->do2 = new DependentObject2;
    }
    public function setData($data1, $data2)
    {
        $this->do1->setData($data1);
        $this->do2->setData($data2);
    }
    /** @return String[] */
    public function getData()
    {
        return [
            $this->do1->getData(),
            $this->do2->getData(),
        ];
    }
}
class CompositeEntity
{
    /** @var CoarseGrainedObject $cgo */
    private $cgo;
    public function __construct()
    {
        $this->cgo = new CoarseGrainedObject();
    }
    public function setData($data1, $data2)
    {
        $this->cgo->setData($data1, $data2);
    }
    /** @return String[] */
    public function getData()
    {
        return $this->cgo->getData();
    }
}
class Client {
    /** @var CompositeEntity $entity */
    private  $entity;
    public function __construct()
    {
        $this->entity = new CompositeEntity();
    }
    public function printData(){
        $data = $this->entity->getData();
        foreach($data as $item){
            echo "Data: " . $item . "\r\n";
        }
    }
    public function setData($data1, $data2){
        $this->entity->setData($data1, $data2);
    }
}

header('Content-Type: text/plain');

$client = new Client();
$client->setData("Test", "Data");
$client->printData();
$client->setData("Second Test", "Data1");
$client->printData();
